/*
    Copyright 2007-2011 Patrik Jonsson, sunrise@familjenjonsson.org

    This file is part of Sunrise.

    Sunrise is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    Sunrise is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Sunrise.  If not, see <http://www.gnu.org/licenses/>.

*/

/** \file

    Helper functions to create grids of various types, used by the
    mcrx-stage classes. \ingroup mcrx */

// $Id$

#include "create_grid.h"
#include "grid-fits.h"


/** Helper function to create a full_sed_grid<adaptive_grid>
    object. The extremely ugly syntax with the grid pointer argument
    is so the compiler can resolve which template we are talking
    about, and it has to be a pointer because we can't just create an
    instance of the grid classes. */
boost::shared_ptr<mcrx::full_sed_grid<mcrx::adaptive_grid> > 
mcrx::create_grid(CCfits::FITS& input_file, const density_generator& gen, 
		  int n_lambda, full_sed_grid<mcrx::adaptive_grid>*)
{
  typedef mcrx::full_sed_grid<adaptive_grid> T_grid;
  typedef T_grid::T_data T_data;

  CCfits::ExtHDU& structure_hdu = open_HDU(input_file, "GRIDSTRUCTURE");
  CCfits::ExtHDU& data_hdu = open_HDU(input_file, "GRIDDATA");

  // first create the adaptive grid
  boost::shared_ptr<adaptive_grid<T_data> > gg
    (new adaptive_grid<T_data> (structure_hdu));

  // and then the full_sed_grid
  return boost::shared_ptr<T_grid>
    (new T_grid (gg, structure_hdu, data_hdu, gen, n_lambda));
}

#ifdef WITH_AREPO

/** Helper function to create a full_sed_grid<arepo_grid>
    object. The extremely ugly syntax with the grid pointer argument
    is so the compiler can resolve which template we are talking
    about, and it has to be a pointer because we can't just create an
    instance of the grid classes. */
boost::shared_ptr<mcrx::full_sed_grid<mcrx::arepo_grid> >
mcrx::create_grid(CCfits::FITS&, const density_generator& gen, 
		  int n_lambda, full_sed_grid<mcrx::arepo_grid>*)
{
  typedef mcrx::full_sed_grid<arepo_grid> T_grid;
  typedef T_grid::T_data T_data;

  boost::shared_ptr<arepo_grid<T_data> > gg (new arepo_grid<T_data> ());

  return boost::shared_ptr<T_grid> (new T_grid (gg, gen, n_lambda));

}

#endif
